<?php

namespace app\admin\controller;

use think\Db;
use app\common\controller\order\Orderget;

class User extends Common
{
//    用户列表页面
    public function index()
    {
    	
        $qudao = $this->qudao(); //调用渠道数据
        $this->assign('qudao', $qudao);

        return $this->fetch();
    }

    //    注册未申请
    public function index1()
    {
        $qudao = $this->qudao(); //调用渠道数据
        $this->assign('qudao', $qudao);

        return $this->fetch();
    }

    //    还款未借
    public function index2()
    {
        $qudao = $this->qudao(); //调用渠道数据
        $this->assign('qudao', $qudao);

        return $this->fetch();
    }

    //	用户编辑页面
    public function editss()
    {
        $ID = input('ID');
        $data = Db::table('xb_mem_info')->where('ID', $ID)->find();
        $this->assign('data', $data);

        return $this->fetch();
    }

    //	用户编辑操作
    public function edit()
    {
        $this->logs('用户编辑');
        $data = input();
        $re = Db::table('xb_mem_info')->update($data);
        if ($re) {
            show_success();
        } else {
            show_error();
        }
    }

    //	 用户列表页面数据
    public function get_list()
    {
        $page = input('page');
        $limit = input('limit');
        $songsong = input('songsong');
        $Orderget = new Orderget();
        $where = $Orderget->sorch();
        if ($songsong) {
            if ($songsong == '3') {//全部用户
                $re = Db::table('xb_mem_info')->page($page, $limit)->where($where)->order('ID DESC')->select();
            }
            if ($songsong == '1') {//注册未申请
                $where['Status'] = '1';
                $re = Db::table('xb_mem_info')->page($page, $limit)->where($where)->order('ID DESC')->select();
            }
            if ($songsong == '2') {//还款未借    这个列表分页不能用  到时候有数据了 在做调整
                $re = [];
                $where['Status'] = '2';
                $data = Db::table('xb_mem_info')->where($where)->order('ID DESC')->select();
                foreach ($data as $k => $v) {
                    $wherecc['UserID'] = $v['ID'];
                    $applylist = Db::table('xb_loans_applylist')->where($wherecc)->order('ApplyTime', 'desc')->limit(1)->find();
                    if ($applylist['LoanStatus'] == '3') {
                        $re[] = $v;
                    }
                }
            }
        }
        //		p($re);die;
//
        foreach ($re as $k => $v) {
            //			最后还款时间
            $re[$k]['sj_huankuanshijian'] = Db::table('xb_loans_applylist')->where(['UserID' => $v['ID'], 'LoanStatus' => '3'])->order('ID', 'desc')->limit(1)->value('SjFkTime');
            //			 借款次数
            $re[$k]['jiekuan_num'] = Db::table('xb_loans_applylist')->where(['UserID' => $v['ID'], 'LoanStatus' => '3'])->count();
            //		用户状态
            if ($v['Status'] == '1') {
                $re[$k]['Status'] = '待审核';
            }
            if ($v['Status'] == '2') {
                $re[$k]['Status'] = '审核通过';
            }
            if ($v['Status'] == '3') {
                $re[$k]['Status'] = '禁用';
            }
            if ($v['Status'] == '4') {
                $re[$k]['Status'] = '黑名单';
            }
            //			客户端
            if ($v['Retype'] == '0') {
                $re[$k]['Retype'] = '网页';
            }
            if ($v['Retype'] == '1') {
                $re[$k]['Retype'] = '安卓';
            }
            if ($v['Retype'] == '2') {
                $re[$k]['Retype'] = '苹果';
            }
            //			认证信息
            if ($v['isID'] == '1') {
                $re[$k]['renzheng'] = '<span style="color:green;">身,</span>';
            } else {
                $re[$k]['renzheng'] = '<span style="color:red;">身,</span>';
            }
            if ($v['isMobile'] == '1') {
                $re[$k]['renzheng'] = $re[$k]['renzheng'].'<span style="color:green;">手,</span>';
            } else {
                $re[$k]['renzheng'] = $re[$k]['renzheng'].'<span style="color:red;">手,</span>';
            }
            if ($v['isSocial'] == '1') {
                $re[$k]['renzheng'] = $re[$k]['renzheng'].'<span style="color:green;">社,</span>';
            } else {
                $re[$k]['renzheng'] = $re[$k]['renzheng'].'<span style="color:red;">社,</span>';
            }
            if ($v['isBank'] == '1') {
                $re[$k]['renzheng'] = $re[$k]['renzheng'].'<span style="color:green;">银</span>';
            } else {
                $re[$k]['renzheng'] = $re[$k]['renzheng'].'<span style="color:red;">银</span>';
            }
            $re[$k]['TgadminID'] = Db::table('xb_tg_admin')->where(['ID' => $v['TgadminID']])->value('Name');
        }

          	
        if ($songsong == '2') {
            $cuont = count($re);
            $star = ($page - 1) * $limit; //开始截取位置
        $re = array_slice($re, $star, $limit); //分页处理
        songsong($re, $cuont);
        } else {
            $cuont = Db::table('xb_mem_info')->where($where)->order('ID DESC')->count('ID');
            songsong($re, $cuont);
        }
    }

    //	详情页面
    public function detail()
    {
        $this->get_xingqing_yonghu();

        return $this->fetch();
    }

    //催收记录
    public function get_list_cuishou_jilu()
    {
        $ID = input('ID'); //用户ID
        $page = input('page');
        $limit = input('limit');
        $re = Db::table('xb_beizhu')->where(['UserID' => $ID])->select(); //用户ID
        foreach ($re as $k => $v) {
            $re[$k]['adminID'] = Db::table('xb_sys_administrator')->where(['ID' => $v['adminID']])->value('UserName');
        }
        //数据分页
        $cuont = count($re);
        $star = ($page - 1) * $limit; //开始截取位置
        $re = array_slice($re, $star, $limit); //分页处理
        if ($re) {
            songsong($re, $cuont);
        } else {
            songsong($re, $cuont);
        }
    }
}
